<template>
  <div id="nav">
    <top-header>{{ headerTitle}}</top-header>
    <search-input :placeholder="placeholder" :maxlength="maxlength"></search-input>
  </div>
  <router-view/>
  <tab-bar></tab-bar>
</template>
<script>
import TopHeader from '@/components/TopHeader/index.vue'
import SearchInput from '@/components/SearchInput/index.vue'
import TabBar from '@/components/TabBar/index.vue'
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
import { watch } from 'vue';
export default {
  components: {
    TopHeader,
    TabBar,
    SearchInput,
  },
  setup() {
    const store = useStore()  //获取store
    const router = useRouter()
    console.log(store.state)
    // console.log(router.currentRoute.value.name)
    watch (
      () => router.currentRoute.value.name,   //监视路由名称的突变（切换路由名称）
      (value) => {
        // console.log(value)
        store.commit('setHeaderTitle', value)  //提交突变标题
        store.commit('setPlaceholder', value)   
        store.commit('setMaxlength', value)   
        store.commit('setField', value)   
      }
    )
    
    return store.state  //把vuex中的数据暴露出去
  }
}
</script>

<style lang="less">
// 做全局样式
.container{
	padding: .82rem 0 .44rem 0;
	box-sizing: border-box;
}
</style>
